<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <link rel="icon" type="image/x-icon" href="/signin/favicon.ico"/>
    <title>登录</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }

        body {
            font: 12px/1.5 "Microsoft YaHei", tahoma, arial, 'Hiragino Sans GB', '\5b8b\4f53', sans-serif;
        }

        ul, li, i {
            list-style: none;
            font-style: normal
        }

        form {
            width: 500px;
            margin: 80px auto;
            color: #6C6C6C;
        }

        p {
            height: 30px;
            line-height: 30px;
            margin-bottom: 26px;
            position: relative;
        }

        label {
            float: left;
            width: 100px;
            text-align: right;
            font-size: 14px;
        }

        span {
            font-size: 12px;
        }

        #sub {
            list-style: none;
            background-color: #2d8cf0;
            color: #fff !important;
            margin-top: 0px;
            line-height: 36px;
            height: 36px;
            width: 120px;
            display: inline-block;
            text-align: center;
            text-decoration: none;
            vertical-align: middle;
            cursor: pointer;
            font-size: 14px;
            font-weight: 700;
            border-radius: 2px;
            padding: 0 20px;
            margin-left: 80px;
            margin-top: 10px;
            outline-color: #ffffff;
        }

        #home {
            list-style: none;
            background-color: #2d8cf0;
            border: 1px solid #2d8cf0;
            color: #fff !important;
            margin-top: 0px;
            line-height: 36px;
            height: 36px;
            width: 120px;
            display: inline-block;
            text-align: center;
            text-decoration: none;
            vertical-align: middle;
            cursor: pointer;
            font-size: 14px;
            font-weight: 700;
            border-radius: 2px;
            padding: 0 20px;
            margin-left: 50px;
            margin-top: 10px;
        }

        p input {
            float: left;
            font-size: 12px;
            color: #6C6C6C;
            vertical-align: middle;
            border: 1px solid #ddd;
            height: 24px;
            line-height: 24px;
            width: 300px;
            padding: 3px 10px;
            margin-right: 8px;
        }

        #yzm, #imgCode {
            width: 120px;
        }

        .getYzm {
            background: #FFF1E8;
            border: 1px solid #FF751A;
            height: 100%;
            white-space: nowrap;
            padding: 0 4px;
            min-width: 188px;
            color: #FF6A00;
            border-radius: 3px;
        }

        p span {
            display: none;
            font-size: 14px;
            color: #ff5243;
            position: absolute;
            width: 160px;
            top: 1px;
            left: 432px;
        }

        span img {
            width: 16px;
            margin-bottom: -3px;
        }

        span b {
            font-weight: 400;
            font-size: 12px;
        }

        p.err input {
            border-color: #ff5243;
        }

        p.err span {
            display: block;
        }

        #kaptcha {
            display: block;
        }

        .step li {
            float: left;
            width: 33%;
            height: 54px;
            position: relative;
        }

        .step span {
            display: block;
            height: 30px;
            line-height: 30px;
            position: relative;
            text-shadow: 0 1px 0 #fff;
            top: 34px;
            left: -50px;
            color: #b7b7b7;
            font-size: 14px;
        }

        .step .step-end {
            position: absolute;
            top: 0;
            right: -140px;
            width: 150px;
            zoom: 1;
        }

        .step .active .iconfont:before {
            background: #00C1DE;
        }

        .step .active span {
            color: #00C1DE;
        }

        .div-bar {
            background: #2d8cf0;
            width: 100%;
            height: 50px;
            text-align: center;
            line-height: 50px;
            font-size: 20px;
        }

        #mitit {
            font-weight: 400;
            margin-left: 100px;
            color: #c3c3c3;
        }
    </style>
</head>
<body>
<div class="div-bar"><font color="white">注册用户</font></div>

<form>
    <p class="uname">
        <label for="uname">姓名：</label>
        <input type="text" name="uname"/>
        <span><img src="/signin/image/err.png"/><b>请输入姓名</b></span>

    </p>
    <p class="user">
        <label for="user">账户：</label>
        <input type="text" name="user"/>
        <span><img src="/signin/image/err.png"/><b>账户已存在</b></span>
    </p>

    <p class="pwd1">
        <label>密码：</label>
        <input type="text" id="pass1"/>
        <span><img src="/signin/image/err.png"/><b>请输入密码</b></span>
        <b id="mitit">长度为6-16个字符，必须包含字母、数字、符号中至少2种</b>
    </p>
    <p class="pwd2">
        <label>确认密码：</label>
        <input type="text" id="pass2"/>
        <span><img src="/signin/image/err.png"/><b>两次输入的密码不一致</b></span>
    </p>

    <p class="email">
        <label for="email">邮箱：</label>
        <input type="text" name="email"/>
        <span><img src="/signin/image/err.png"/><b>邮箱格式不正确</b></span>
    </p>
    <p class="imgcode">
        <label for="yzm">验证码：</label>
        <input type="text" id="imgCode"/>
        <img src="/signin/kaptcha" id='kaptcha'/>
        <span><img src="/signin/image/err.png"/><b>验证码错误</b></span>
    </p>

    <p><input id="sub" type="button" value="注册"/><label> </label><input id="home" type="button" value="返回"/></p>
</form>

<script src="/signin/js/jQuery.3.3.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var flg_k = $.inArray(' ', pass1);
    var flg = true;
    $('#sub').click(function (e) {


        var uname = $('input[name=uname]').val();
        var user = $('input[name=user]').val();
        var pass1 = $('#pass1').val();
        var pass2 = $('#pass2').val();
        var email = $('input[name=email]').val();
        var imgCode = $('#imgCode').val();
        $('p').removeClass('err')
        if (uname == '') {
            err('.uname', '请输入姓名')
        } else if (user == '') {
            err('.user', '请输入账户')
        } else if (!filter.test(email)) {
            $('.email').addClass('err')
        } else if (pass1 == '') {
            err('.pwd1', '密码不能为空')
        } else if (flg_k != -1) {
            err('.pwd1', '密码不能有空格')
        } else if (pass1.length < 6 || pass1.length > 16) {
            err('.pwd1', '密码长度在6-16位之间')
        } else if (imgCode == '') {
            err('.imgcode', '请输入图形验证码')
        } else {

            $('.pwd1').removeClass('err')
            if (pass2 == '') {
                err('.pwd2', '请确认密码')

            } else if (pass1 != pass2) {
                err('.pwd2', '两次输入的密码不一致')
            } else {
                $('.pwd2').removeClass('err')
                var mail = {
                    name: uname,
                    email: email,
                    pass: pass1,
                    imageCode: imgCode,
                    account: user
                }

                $('#sub').attr('disabled', "true");
                $('#sub').css('background', "#c5c8ce");
                $.post("/signin/user/register/save", mail, function (result) {
                    console.log(result.code)
                    if (result.code == 200) {
                        window.location.href = "/signin/user/register/success";
                    } else if (result.code == 401) {
                        err('.imgcode', '图形验证码错误')
                        $('#kaptcha').trigger("click");
                    } else if (result.code == 501) {
                        err('.pwd1', "密码格式不正确")
                        err('.pwd2', "密码格式不正确")
                    } else if (result.code == 402) {
                        err('.user', '账户名已存在')
                    }
                    $('#sub').removeAttr("disabled");
                    $('#sub').css('background', "#2d8cf0");


                    $('#kaptcha').trigger("click");
                });
            }
        }
    })


    $('#home').click(function () {
        $.post("/signin/user/gohome", null, function (result) {
            window.location.href = result.result;
        });

    })


    $("#kaptcha").click(function () {
        $("#kaptcha").attr('src', '/signin/kaptcha?' + Math.floor(Math.random() * 100)).fadeIn();
    });

    function err(name, txt) {
        $(name).addClass('err');
        $(name).find('span b').html(txt)

    }

</script>
</body>
</html>
